package com.tlw.leave.controller;

import com.tlw.leave.constant.R;
import com.tlw.leave.entity.Information;
import com.tlw.leave.entity.InformationRecord;
import com.tlw.leave.entity.Vo.Conditions;
import com.tlw.leave.entity.Vo.LeaveTime;
import com.tlw.leave.entity.Vo.PageVo;
import com.tlw.leave.handle.Aspect;
import com.tlw.leave.service.InformationRecordService;
import com.tlw.leave.service.InformationService;
import io.swagger.annotations.ApiOperation;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.awt.print.Pageable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Optional;

@RestController
@CrossOrigin
@RequestMapping("/Information")
public class informationController {

    private final static Logger LOGGER = LoggerFactory.getLogger(informationController.class);

    @Autowired
    private InformationService informationService;

    @Autowired
    private InformationRecordService informationRecordService;

    @Transactional
    @ApiOperation(value="保存Information")
    @RequestMapping(value = "saveInformation",method = RequestMethod.POST)
    public R saveInformation(@RequestBody Information information) {
        return R.ok().data("add",informationService.addInformation(information));
    }

    @ApiOperation(value="删除Information")
    @RequestMapping(value = "deleteInformation/{id}",method = RequestMethod.DELETE)
    public void deleteInformation(@PathVariable Integer id){
        informationService.deleteInformation(id);
    }


    @ApiOperation(value="更新Information")
    @RequestMapping(value = "updateInformation",method = RequestMethod.POST)
    public Information updateInformation(@RequestBody Information information){
        return informationService.updateInformation(information);
    }

    @ApiOperation(value="查询所有Information")
    @RequestMapping(value = "findList",method = RequestMethod.GET)
    public List<Information>  findList(){
        LOGGER.info(new Date()+"用户执行了"+Thread.currentThread().getStackTrace()[1].getMethodName());  //查看当前方法名
        return informationService.finadAll();
    }


    @ApiOperation(value="根据id查询Information")
    @RequestMapping(value = "getInformationById/{id}",method = RequestMethod.GET)
    public R getInformationById(@PathVariable Integer id){
        LOGGER.info(new Date()+"用户执行了"+Thread.currentThread().getStackTrace()[1].getMethodName());  //查看当前方法名
        return R.ok().data("id",informationService.getInformationById(id));
    }

    @ApiOperation(value="根据名字查询Information")
    @RequestMapping(value = "finadNameInformationList/{name}",method = RequestMethod.GET)
    public R finadNameInformationList(@PathVariable String name){
        LOGGER.info(new Date()+"用户执行了"+Thread.currentThread().getStackTrace()[1].getMethodName());  //查看当前方法名
        return R.ok().data("nameList", informationService.findInformationName(name));
    }

    @ApiOperation(value="根据分页信息查询Information")
    @RequestMapping(value = "getPageableList",method = RequestMethod.GET)
    public R getPageableList(PageVo pageVo){
        return R.ok().data("getPageableList",informationService.getPageableList(pageVo));
    }

    @RequestMapping(value = "getPageListTime",method = RequestMethod.GET)
    public List<Information> getPageListTime(LeaveTime leaveTime){
        return informationService.getTimeScope(leaveTime);
    }

    @RequestMapping(value = "getConditionsList",method = RequestMethod.GET)
    public R getConditionsList(Conditions conditions){
        return R.ok().data("conditionsList",informationService.getconditionsListInformation(conditions));
    }
}
